/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.constant.enums;

import com.comac.ins.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 平台建设关联关系类型
 *
 * @author hxloongs
 * @date 2025-3-13
 */
@AllArgsConstructor
@Getter
public enum IsfdBusinessDatabaseTypeEnum {
    ROOT("root", "模型树的根节点"),
    SCENE("scene", "场景"),
    SYSTEM("system", "系统"),
    DATABASE_1("database_1", "要素数据库一级库"),
    DATABASE_2("database_2", "要素数据库二级库"),
    MODEL("model", "普通模型"),
    COMMON_MODEL("common_model", "通用模型");

    private final String value;
    private final String desc;

    public static String getDescByValue(String value) {
        IsfdBusinessDatabaseTypeEnum isfdBusinessDatabaseTypeEnum = forValue(value);
        if (isfdBusinessDatabaseTypeEnum == null) {
            return null;
        }
        return isfdBusinessDatabaseTypeEnum.getDesc();
    }

    public static IsfdBusinessDatabaseTypeEnum forValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (IsfdBusinessDatabaseTypeEnum isfdBusinessDatabaseTypeEnum : IsfdBusinessDatabaseTypeEnum.values()) {
            if (isfdBusinessDatabaseTypeEnum.getValue().equals(value)) {
                return isfdBusinessDatabaseTypeEnum;
            }
        }
        return null;
    }

    public static IsfdBusinessDatabaseTypeEnum forDesc(String desc) {
        if (desc == null) {
            return null;
        }
        for (IsfdBusinessDatabaseTypeEnum isfdBusinessDatabaseTypeEnum : IsfdBusinessDatabaseTypeEnum.values()) {
            if (desc.equals(isfdBusinessDatabaseTypeEnum.getDesc())) {
                return isfdBusinessDatabaseTypeEnum;
            }
        }
        return null;
    }

    /**
     * 判断是不是模型
     */
    public static Boolean isModel(String value) {
        if (StringUtils.isBlank(value)) {
            return Boolean.FALSE;
        }
        if (MODEL.getValue().equals(value) || COMMON_MODEL.getValue().equals(value)) {
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }
}
